package com.learn.project2.controller.admin;

import com.learn.project2.model.bo.admin.goods.GoodsCreateBO;
import com.learn.project2.model.bo.admin.goods.GoodsDeleteBO;
import com.learn.project2.model.bo.admin.goods.GoodsUpdateBO;
import com.learn.project2.model.vo.admin.goods.GoodsCatAndBrandVO;
import com.learn.project2.model.vo.admin.goods.GoodsDetailVO;
import com.learn.project2.model.vo.admin.goods.GoodsListVO;
import com.learn.project2.service.admin.goods.GoodsService;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 曹源
 * @version 1.0
 * @description: 商品管理/商品列表 Admin/goods的控制方法
 * @date 2022/1/6 21:08
 */
@RestController
@RequestMapping("admin/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    Result result;

    /**
     * @description: 商品管理/商品列表/查询 Admin/goods/list的控制方法
     * @param:
     * @return:
     * @author 曹源
     * @date: 2022-01-08 09:21
     */
    @RequestMapping("list")
    @RequiresPermissions("admin:goods:list")
    public Result list(Integer page, Integer limit, Integer goodsSn, String name, String sort, String order, Integer goodsId) {
        GoodsListVO goodsListVO = goodsService.selectlist(page, limit, goodsSn, name, sort, order, goodsId);
        return result.ok(goodsListVO);
    }

    /**
     * @description: 商品管理/商品列表/添加 Admin/goods/create的控制方法
     * @param:
     * @return:
     * @author 曹源
     * @date: 2022-01-08 11:07
     */
    @PostMapping("create")
    @RequiresPermissions("admin:goods:create")
    public Result create(@RequestBody GoodsCreateBO goodsCreateBO) {
        goodsService.insert(goodsCreateBO);
        return result.ok();
    }

    /**
     * @description: 商品管理/商品列表/编辑 Admin/goods/update的控制方法
     * @param:
     * @return:
     * @author 曹源
     * @date: 2022-01-08 17:26
     */
    @PostMapping("update")
    @RequiresPermissions("admin:goods:update")
    public Result update(@RequestBody GoodsUpdateBO goodsUpdateBO) {
        goodsService.updateGoods(goodsUpdateBO);
        return result.ok();
    }

    /**
     * @description: 商品管理/商品列表/删除 Admin/goods/delete的控制方法
     * @param:
     * @return:
     * @author 曹源
     * @date: 2022-01-08 16:29
     */
    @RequestMapping("delete")
    @RequiresPermissions("admin:goods:delete")
    public Result delete(@RequestBody GoodsDeleteBO goodsDeleteBO) {
        goodsService.delete(goodsDeleteBO);
        return result.ok();
    }

    /**
     * @description: 商品管理/商品列表/详细信息 Admin/goods/detail的控制方法
     * @param:
     * @return:
     * @author 曹源
     * @date: 2022-01-08 14:44
     */
    @RequestMapping("detail")
    @RequiresPermissions("admin:goods:read")
    public Result detail(Integer id) {
        GoodsDetailVO goodsDetailVO = goodsService.selectDetail(id);
        return result.ok(goodsDetailVO);
    }

    /**
     * @description: 商品管理/商品列表/类别和商标信息 Admin/goods/catAndBrand的控制方法
     * @param:
     * @return:
     * @author 曹源
     * @date: 2022-01-08 11:14
     */
    @RequestMapping("catAndBrand")
    public Result catAndBrand() {
        GoodsCatAndBrandVO catAndBrandVO = goodsService.selectCatAndBrand();
        return result.ok(catAndBrandVO);
    }
}
